<?php

namespace App\Http\Controllers\Admin\Users;

use App\Services\Admin\Users\TagService;
use App\Http\Controllers\Controller;

class TagController extends Controller
{
    public function tagList (){
        try {
            $size = request()->get('size',10);
            $page = request()->get('page',1);
            $type = request()->get('tagclas','');
            $offset = ($page - 1) * $size;
            $res = TagService::tagList($size, $offset, $type);
            return self::success(200,'查询完成',$res);
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }

    public function tagAdd (){
        try {
            $data = request()->all();
            $res = TagService::tagAdd($data);
            return self::success(200,'标签添加成功');
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }

    public function classAdd (){
        try {
            $data = request()->all();
            $res = TagService::classAdd($data);
            return self::success(200,'标签添加成功');
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }

    public function tagUpdate (){
        try {
            $data = request()->all();
            $res = TagService::tagUpdate($data);
            return self::success(200,'修改成功');
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }

    public function tagDelete (){
        try {
            $id = request()->get('id');
            $res = TagService::tagDelete($id);
            return self::success(200,'删除成功');
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }

    public function sendTag (){
        try {
            $userid = request()->post('userid');
            $tag = request()->post('tag');
            $res = TagService::sendTag($userid,$tag);
            return self::success(200,'标签设置成功');
        } catch (\Exception $exception){
            return self::success(2001,$exception->getMessage());
        }
    }
}
